using System.Web.Mvc;
using AgileBoard.Core;
using AgileBoard.Infrastructure.Extensions;
using AgileBoard.Web.Controllers.ViewModel;
using SharpArch.Core.PersistenceSupport;

namespace AgileBoard.Web.Controllers
{
    public class BoardController : Controller
    {
        private readonly IRepository<Project> projectRepository;
        private readonly UserProfile userProfile;

        public BoardController(IRepository<Project> projectRepository, UserProfile userProfile)
        {
            this.projectRepository = projectRepository;
            this.userProfile = userProfile;
        }

        public ActionResult Current()
        {
            var project = projectRepository.Get(userProfile.ProjectId);
            var lastIteration = project.Iterations.Count > 0 ? project.Iterations.MaxBy(x => x.Id) : new Iteration();

            return View(lastIteration);
        }
    }
}